#include <iostream>
using namespace std;
#include <vector>
#include <string>

// 常用查找算法 count

// 1、统计内置数据类型
void test1()
{
    vector<int>v;

    v.push_back(10);
    v.push_back(40);
    v.push_back(20);
    v.push_back(50);
    v.push_back(30);
    v.push_back(10);
    v.push_back(10);

    int num = count(v.begin(), v.end(), 10);

    cout << "10的元素个数为：" << num << endl;
}

// 2、统计自定义数据类型
class Person
{
public:
    string name;
    int age;

    Person(string name, int age)
    {
        this->name = name;
        this->age = age;
    }

    bool operator==(const Person& p)
    {
        if (this->age == p.age)
        {
            return true;
        }
        else
        {
            return false;
        }

    }
};

void test2()
{
    vector<Person>v;

    // 创建数据
    Person p1("孙悟空", 999);
    Person p2("唐僧", 35);
    Person p3("猪八戒", 800);
    Person p4("沙僧", 35);
    Person p5("小白龙", 1000);

    // 放入到容器中
    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);

    Person p("诸葛亮", 35);

    int num = count(v.begin(), v.end(), p);

    cout << "和诸葛亮同岁数的人员个数为：" << num << endl;
}

int main()
{
    test1();
    cout << "-----------------------" << endl;
    test2();
    return 0;
}